package com.lee.chapter01;

import com.lee.basic.anno.NotThreadSafe;

@NotThreadSafe
public class Test_Wait {
    private int value;

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public static void main(String[] args) {
        Test_Wait testWait = new Test_Wait();
        Object o = new Object();
        Thread thread1 = new Thread() {
            @Override
            public void run() {
                synchronized (o) {
                    try {
                        // 在该方法的注视中说到：This method should only be called by a thread that is the owner of this object's monitor
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    testWait.setValue(100);
                }
            }
        };

//        Thread thread2 = new Thread() {
//            @Override
//            public void run() {
//                try {
//                    o.wait();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println(testWait.getValue());
//            }
//        };

        thread1.start();
//        thread2.start();
        synchronized (o) {
            o.notifyAll();
        }

    }
}
